//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2009-01-01
// Contains ...
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Text;
using System.Xml.Linq;
using JetBrains.Annotations;
using LargoCommon.Abstract;
namespace LargoCommon.Music
{
///
/// Tonality Change.
///
public sealed class TonalityChange : AbstractChange {
#region Fields
///
/// Harmonic Modality.
///
private HarmonicModality harmonicModality;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
[UsedImplicitly]
public TonalityChange() {
}
///
/// Initializes a new instance of the class.
///
/// The given change.
public TonalityChange(XElement xchange)
: base(xchange) {
Contract.Requires(xchange != null);
//// if (xchange == null) { return; }
this.HarmonicModalityCode = XmlSupport.ReadStringAttribute(xchange.Attribute("HarmonicModalityCode"));
this.ChangeType = MusicalChangeType.Tonality;
}
///
/// Initializes a new instance of the class.
///
/// The given bar.
public TonalityChange(int givenBar)
: base(givenBar, 0, MusicalChangeType.Tonality) {
}
///
/// Initializes a new instance of the class.
///
/// The given bar.
/// The given harmonic modality code.
public TonalityChange(int givenBar, string givenHarmonicModalityCode)
: base(givenBar, 0, MusicalChangeType.Tonality) {
this.HarmonicModalityCode = givenHarmonicModalityCode;
}
#endregion
#region Properties - Xml
///
/// Gets Xml representation.
///
///
/// Property description.
///
public override XElement GetXElement {
get {
var change = base.GetXElement;
change.Add(new XAttribute("HarmonicModalityCode", this.HarmonicModalityCode ?? string.Empty));
return change;
}
}
#endregion
#region Properties
///
/// Gets or sets the harmonic modality code.
///
///
/// The harmonic modality code.
///
[UsedImplicitly]
public string HarmonicModalityCode { get; set; }
///
/// Gets or sets the harmonic modality.
///
///
/// The harmonic modality.
///
[UsedImplicitly]
public HarmonicModality HarmonicModality
{
get
{
if (this.harmonicModality != null)
{
return this.harmonicModality;
}
return this.harmonicModality;
}
set => this.harmonicModality = value;
}
///
/// Gets the modality outline.
///
/// Property description.
[UsedImplicitly]
public string ModalityOutline
{
get
{
var hm = this.HarmonicModality;
if (hm != null)
{
return hm.ToneSchema;
}
return string.Empty;
}
}
#endregion
#region Public methods
///
/// Clones this instance.
///
/// Returns object.
public override object Clone() {
var tmc = new TonalityChange(this.BarNumber) {
HarmonicModalityCode = this.HarmonicModalityCode,
HarmonicModality = this.HarmonicModality
};
//// tmc.BlockModel = this.BlockModel;
return tmc;
}
#endregion
#region String representation
/// String representation of the object.
/// Returns value.
public override string ToString() {
var s = new StringBuilder();
s.AppendFormat(CultureInfo.CurrentCulture, base.ToString());
s.Append("," + this.HarmonicModalityCode);
return s.ToString();
}
#endregion
}
}